package com.zenith.edu.controller;

import com.zenith.common.annotation.request.SecurePostMapping;
import com.zenith.common.result.Result;
import com.zenith.edu.po.dto.EduLiveWatchRecordDTO;
import com.zenith.edu.po.vo.EduLiveWatchRecordVO;
import com.zenith.edu.service.EduLiveWatchRecordService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/edu/live-watch-record")
@Tag(name = "直播观看记录管理", description = "直播观看记录管理接口")
public class EduLiveWatchRecordController {
    
    @Autowired
    private EduLiveWatchRecordService eduLiveWatchRecordService;
    
    @SecurePostMapping(value = "/createLiveWatchRecord", roles = "ROLE_ADMIN", permission = "live-watch-record:create")
    @Operation(summary = "创建直播观看记录")
    public Result<EduLiveWatchRecordVO> createLiveWatchRecord(@RequestBody EduLiveWatchRecordDTO dto) {
        EduLiveWatchRecordVO liveWatchRecordVO = eduLiveWatchRecordService.createLiveWatchRecord(dto);
        return Result.success(liveWatchRecordVO);
    }
    
    @SecurePostMapping(value = "/getLiveWatchRecordById/{id}", roles = "ROLE_ADMIN", permission = "live-watch-record:read")
    @Operation(summary = "根据ID获取直播观看记录详情")
    public Result<EduLiveWatchRecordVO> getLiveWatchRecordById(@PathVariable Long id) {
        EduLiveWatchRecordVO liveWatchRecordVO = eduLiveWatchRecordService.getLiveWatchRecordById(id);
        if (liveWatchRecordVO == null) {
            return Result.fail("直播观看记录不存在");
        }
        return Result.success(liveWatchRecordVO);
    }
    
    @SecurePostMapping(value = "/updateLiveWatchRecord", roles = "ROLE_ADMIN", permission = "live-watch-record:update")
    @Operation(summary = "更新直播观看记录信息")
    public Result<EduLiveWatchRecordVO> updateLiveWatchRecord(@RequestBody EduLiveWatchRecordDTO dto) {
        EduLiveWatchRecordVO liveWatchRecordVO = eduLiveWatchRecordService.updateLiveWatchRecord(dto);
        return Result.success(liveWatchRecordVO);
    }
    
    @SecurePostMapping(value = "/deleteLiveWatchRecord/{id}", roles = "ROLE_ADMIN", permission = "live-watch-record:delete")
    @Operation(summary = "删除指定直播观看记录")
    public Result<Void> deleteLiveWatchRecord(@PathVariable Long id) {
        boolean result = eduLiveWatchRecordService.deleteLiveWatchRecord(id);
        if (!result) {
            return Result.fail("直播观看记录删除失败");
        }
        return Result.success();
    }
    
    @SecurePostMapping("/list")
    @Operation(summary = "获取直播观看记录列表")
    public Result<List<EduLiveWatchRecordVO>> getLiveWatchRecordList() {
        List<EduLiveWatchRecordVO> liveWatchRecordList = eduLiveWatchRecordService.getLiveWatchRecordList();
        return Result.success(liveWatchRecordList);
    }
}